package vis.manage.sys;

import vis.core.common.security.AuthOnlyLogin;
import vis.core.domain.db.SysRole;
import vis.core.domain.search.Psh;
import vis.core.domain.sys.SRS;
import vis.core.service.sys.SysRoleService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manage/system/role")
public class SysRoleController {

    @Resource
    private RedissonClient redisson;

    @Resource
    private SysRoleService sysRoleService;

    @AuthOnlyLogin
    @PostMapping("/allMyRole")
    public SRS<Object> allMyRole() {
        List<SysRole> sysRoleList = sysRoleService.allMyRole();
        return SRS.bySuccess(sysRoleList);
    }

    @PostMapping("/pageMyRole")
    public SRS<Page<SysRole>> pageMyRole(SysRole sysRole, Psh psh) {
        Page<SysRole> page = sysRoleService.pageMyRole(sysRole, psh);
        return SRS.bySuccess(page);
    }

    @PostMapping("/insertRole")
    public SRS<Boolean> insertRole(SysRole sysRole) {
        boolean b = sysRoleService.insert(sysRole);
        return SRS.bySuccess(b);
    }

    @PostMapping("/deleteRole")
    public SRS<Boolean> deleteRole(String ids) {
        boolean b = sysRoleService.delete(ids);
        return SRS.bySuccess(b);
    }

    @PostMapping("/updateRole")
    public SRS<Boolean> updateRole(SysRole sysRole) {
        boolean b = sysRoleService.update(sysRole);
        return SRS.bySuccess(b);
    }

    @PostMapping("/info")
    public SRS<Boolean> info(String id) {
        SysRole sysRole = sysRoleService.info(id);
        return SRS.bySuccess(sysRole);
    }

    @PostMapping("/updateRoleMenu")
    public SRS<Boolean> updateRoleMenu(String roleId, String menuIds) {
        boolean b = sysRoleService.updateRoleMenu(roleId, menuIds);
        return SRS.bySuccess(b);
    }

}
